<template>
	<view>
		<Header title="我的推广" :isHome="true" :isWhite="true"></Header>
		<view class="tabs">
			<view class="tab">
				<p>总人数</p>
				<text>{{ countInfo.count }}</text>
			</view>
			<view class="tab">
				<p>金额</p>
				<text>{{ countInfo.money }}</text>
			</view>
			<view class="tab">
				<p>直推</p>
				<text>{{ countInfo.firstcount }}</text>
			</view>
			<view class="tab">
				<p>间推</p>
				<text>{{ countInfo.secondcount }}</text>
			</view>
		</view>
		<view style="margin: 0 0 30rpx 30rpx; font-weight: 500"> 推广明细 </view>
		<view class="cards">
			<view class="card" v-for="list in list" :key="list">
				<view class="left">
					<view class="up">
						<p>{{ list.adultname ?list.adultname:list.mobile }}</p>
						<view :class="[list.text === '间推' ? 'indirect' : 'direct']">{{list.text}}</view>
					</view>
					<text>上级姓名：{{ list.parentName }}</text>
				</view>
				<view class="rig">{{ list.createtime }}</view>
			</view>
		</view>
		<view class="more">没有更多了</view>
		<view class="poster" @click="goPage('/subpages/zxy/poster')">
			<p>推广海报</p>
		</view>
	</view>
</template>

<script>
	import {
		get
	} from '../../utils/request';
	export default {
		data() {
			return {
				page: 1,
				countInfo: {},
				list: [],
			};
		},
		onReachBottom() {
			this.page++
			this.getTeam()
		},
		onLoad() {
			this.getTeam()
			this.getTeamStatic()
		},
		methods: {
			getTeam() {
				get('/user/get_team?page=' + this.page).then(res => {
						if (res.code == 1) {
							if (this.page == 1) {
								this.list = res.data.data
							} else {
								this.list = this.list.concat(res.data.data)
							}
						}
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
			},
			getTeamStatic() {
				get('/user/get_team_statistics').then(res => {
						this.countInfo = res.data
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
			},
			goPage(url) {
				uni.navigateTo({
					url: url,
				});
			},
		},
	};
</script>

<style lang='scss' scoped>
	.poster {
		background: #fff;
		width: 100%;
		height: 170rpx;
		position: fixed;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);

		p {
			text-align: center;
			font-weight: 500;
			font-size: 32rpx;
			color: #222222;
			padding: 15rpx 35rpx;
			background: #ffd275;
			margin: 30rpx;
			border-radius: 50rpx;
		}
	}

	.more {
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		text-align: center;
	}

	.rig {
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		align-self: flex-end;
	}

	.up {
		display: flex;
		align-items: center;

		p {
			font-weight: 600;
			font-size: 32rpx;
			color: #222222;
			margin: 0 12rpx 8rpx 0;
		}
	}

	.left {
		text {
			font-weight: 400;
			font-size: 24rpx;
			color: #999999;
		}
	}

	.card {
		background: #f0f0f0;
		border: 3rpx solid #dddddd;
		border-radius: 12rpx;
		padding: 32rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.cards {
		margin: 32rpx;
	}

	.tabs {
		background: #fff;
		margin: 30rpx;
		border-radius: 8rpx;
		display: flex;
		justify-content: space-evenly;
		text-align: center;
	}

	.tab {
		padding: 20rpx 30rpx;
		width: 200rpx;
		position: relative;

		&:not(:first-child)::before {
			content: "";
			position: absolute;
			left: 0;
			top: 50%;
			transform: translateY(-50%);
			width: 1rpx;
			height: 50rpx;
			background-color: #e5e5e5;
		}

		p {
			font-weight: 400;
			font-size: 32rpx;
			color: #999999;
			margin-bottom: 8rpx;
		}

		text {
			font-weight: 500;
			font-size: 32rpx;
			color: #fb2f47;
		}
	}

	.indirect {
		color: #222222;
		background-color: #ffd275;
		padding: 3rpx 8rpx;
		border-radius: 5rpx;
		font-size: 24rpx;
	}

	.direct {
		color: #fff;
		background-color: #1a1a1a;
		padding: 3rpx 8rpx;
		border-radius: 5rpx;
		font-size: 24rpx;
	}
</style>